package org.xhy.quickstarter.authority.utils;


import lombok.Data;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

public class R implements Serializable {

    private static final long serialVersionUID = 22L;


    // 响应码，返回状态，返回消息，返回数据
    private int code;

    private Boolean state;

    private String message;

    private Object data;

    private long count;

    public R(){}

    // 成功
    public static R ok(){
        R responseUtils = new R();
        responseUtils.setCode(200);
        responseUtils.setState(true);
        responseUtils.setMessage("成功");
        return responseUtils;
    }

    // 失败
    public static R error(){
        R r = new R();
        r.setCode(201);
        r.setState(false);
        r.setMessage("失败");
        return r;
    }

    public R count(long count){
        this.setCount(count);
        return this;
    }
    public R code(int code){
        this.setCode(code);
        return this;
    }

    public R state(Boolean state){
        this.setState(state);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }
    public R message(String message, Object ... objects){
        this.setMessage(MessageFormat.format(message, objects));
        return this;
    }

    public R data(Object o){
        this.setData(o);
        return this;
    }


    public void setCode(int code) {
        this.code = code;
    }

    public void setState(Boolean state) {
        this.state = state;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public int getCode() {
        return code;
    }

    public Boolean getState() {
        return state;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

    public long getCount() {
        return count;
    }
}
